<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['module:staff:add']"
        >新增
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['module:staff:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['module:customer:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['module:staff:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleCustomExport"
          v-hasPermi="['module:staff:export']"
        >自定义导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>
    <el-dialog title="自定义导出" :visible.sync="customOpen" width="500px" append-to-body>
      <el-checkbox-group v-model="checkList" class="checkBox">
        <el-checkbox label="name" class="label" >姓名</el-checkbox>
        <el-checkbox label="gender" class="label">性别</el-checkbox>
<!--        <el-checkbox label="age" class="label">年龄</el-checkbox>-->
        <el-checkbox label="deptName" class="label">部门</el-checkbox>
        <el-checkbox label="idCardNumber"  class="label">身份证号码</el-checkbox>
        <el-checkbox label="telephone"  class="label">联系电话</el-checkbox>
        <el-checkbox label="entryTime"  class="label">入职时间</el-checkbox>
        <el-checkbox label="contractStartTime"  class="label">劳动合同签约时间</el-checkbox>
        <el-checkbox label="contractEndTime"  class="label">劳动合同终止时间</el-checkbox>
        <el-checkbox label="email"  class="label">邮箱</el-checkbox>
        <el-checkbox label="status"  class="label">状态</el-checkbox>
        <el-checkbox label="admissionTime"  class="label">入学时间</el-checkbox>
        <el-checkbox label="bank"  class="label">开户行</el-checkbox>
        <el-checkbox label="bankCardNo"  class="label">银行卡号</el-checkbox>
        <el-checkbox label="birthday"  class="label">出生年月</el-checkbox>
        <el-checkbox label="commercialInsurance"  class="label">是否缴纳商业险</el-checkbox>
        <el-checkbox label="contactName"  class="label">紧急联系人名称</el-checkbox>
        <el-checkbox label="relationship"  class="label">紧急联系人关系</el-checkbox>
        <el-checkbox label="contactTelephone"  class="label">紧急联系人电话</el-checkbox>
        <el-checkbox label="email"  class="label">邮箱</el-checkbox>
        <el-checkbox label="graduationSchool"  class="label">毕业院校</el-checkbox>
        <el-checkbox label="admissionTime"  class="label">入学时间</el-checkbox>
        <el-checkbox label="healthStatus"  class="label">健康状况</el-checkbox>
        <el-checkbox label="leaveDate"  class="label">离职日期</el-checkbox>
        <el-checkbox label="admissionTime"  class="label">入学时间</el-checkbox>
        <el-checkbox label="marriage"  class="label">婚姻</el-checkbox>
        <el-checkbox label="nativePlace"  class="label">籍贯</el-checkbox>
        <el-checkbox label="politicalOutlook"  class="label">政治面貌</el-checkbox>
        <el-checkbox label="post"  class="label">职务</el-checkbox>
      </el-checkbox-group>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getinfo">确 定</el-button>
        <el-button @click="customOpen=false">取 消</el-button>
      </div>
    </el-dialog>

    <el-table :border="true" v-loading="loading" :data="staffList" @selection-change="handleSelectionChange">

      <el-table-column type="selection" width="80px" align="center"/>
      <el-table-column fixed type="index" width="80px" align="center" label="序号" />
      <el-table-column fixed label="姓名" align="center" prop="name" v-if="columns[0].visible"/>

      <el-table-column fixed label="移动" align="center" width="100">
        <template slot-scope="scope">
          <i class="el-icon-top" style="color:red;font-weight: bold;width: 30px" v-if="scope.$index!==0" @click="upFn(scope.$index,scope.row)"></i>
          <i class="el-icon-bottom" style="color:blue;font-weight: bold;width: 30px" @click="downFn(scope.$index,scope.row)"></i>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="gender" v-if="columns[1].visible"/>
      <el-table-column label="部门" align="center" prop="deptName" v-if="columns[3].visible"/>
      <el-table-column label="公司" align="center" prop="company"/>
      <el-table-column label="职级" align="center" prop="staffRank"/>
      <el-table-column label="类型" align="center" prop="staffType"/>
      <el-table-column label="是否打卡" align="center" prop="isClock"/>
      <el-table-column label="工作时长" align="center" prop="clockTime"/>
<!--      <el-table-column label="年龄" align="center" prop="age" v-if="columns[2].visible"/>-->
      <el-table-column width="170" label="身份证号码" align="center" prop="idCardNumber" v-if="columns[4].visible"/>
      <el-table-column label="联系电话" width="120" align="center" prop="telephone" v-if="columns[5].visible"/>
      <el-table-column label="入职时间" align="center" prop="entryTime" width="120" v-if="columns[6].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="劳动合同签约时间" align="center" prop="contractStartTime" width="180" v-if="columns[7].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="劳动合同终止时间" align="center" prop="contractEndTime" width="180" v-if="columns[8].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="邮箱" width="160" align="center" prop="email" v-if="columns[9].visible"/>
      <el-table-column label="状态" align="center" prop="status" v-if="columns[10].visible"/>
      <el-table-column label="状态修改" align="center" prop="status" width="90" v-if="columns[11].visible">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="statefn(scope.row)"  >
            修改状态
          </el-button>
        </template>
        >
      </el-table-column>
      >
      <el-table-column label="员工详情" align="center" width="120" v-if="columns[12].visible">
        <template slot-scope="scope">
          <el-button @click="DetailPagesfn(scope.row)" size="mini" type="primary">
            查看详情
          </el-button>
        </template>

      </el-table-column>
      >

      <el-table-column label="员工经历" align="center" prop="expect" width="90" v-if="columns[13].visible">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="openStaffHistoy(scope.row)">查看经历</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="120px" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['module:staff:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['module:staff:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改员工管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-form :inline="true" ref="form" :model="form" :rules="rules" label-width="140px">
        <el-form-item label="姓名" prop="name">
          <el-input style="width: 180px" v-model="form.name" placeholder="请输入姓名">
            <template slot="append">
              <el-button type="primary" @click="openusername(0)">
                请输入姓名
              </el-button>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-radio v-model="form.gender" label="0">男</el-radio>
          <el-radio v-model="form.gender" label="1">女</el-radio>
        </el-form-item>

<!--        <el-form-item label="年龄" prop="age">-->
<!--          <el-input style="width: 180px" v-model="form.age" placeholder="请输入年龄"/>-->
<!--        </el-form-item>-->

        <el-form-item label="出生年月" prop="birthday">
          <el-date-picker
            style="width: 180px"
            v-model="form.birthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="类型" prop="staffType">
          <!--          <el-input style="width: 180px" v-model="form.staffType" placeholder="请输入类型"/>-->
          <el-select v-model="form.staffType" placeholder="请选择" style="width: 180px">
            <el-option
              v-for="item in staffTypeEnum"
              :key="item.dictCode"
              :label="item.label"
              :value="item.dictLabel">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="归属部门" prop="deptName">
          <el-cascader
            style="width: 480px"
            v-model="value"
            :options="deptlist"
            :props="optionsProp"
            size="medium "
            placeholder="请输入归属部门"
            @change="handleChange"></el-cascader>
        </el-form-item>

<!--        <el-form-item label="岗位" prop="title">-->
<!--          <el-input style="width: 180px" v-model="form.title" placeholder="请输入岗位"/>-->
<!--        </el-form-item>-->

        <el-form-item label="公司" prop="company">
          <el-input style="width: 180px" v-model="form.company" placeholder="请输入公司" :disabled="true"/>
        </el-form-item>
        <el-form-item label="职级" prop="rankId">
<!--          <el-input style="width: 180px" v-model="form.staffRank" placeholder="请输入职级"/>-->
          <el-select @change="changepost" v-model="form.rankId" placeholder="请选择职级" style="width: 180px">
            <el-option
              v-for="item in postlist"
              :key="item.postId"
              :label="item.postName"
              :value="item.postId"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工作时长" prop="clockTime">
          <el-input-number v-model="form.clockTime" controls-position="right" :min="0" :max="10" style="width: 180px"></el-input-number>
        </el-form-item>
        <el-form-item label="是否打卡" prop="isClock">
          <el-radio style="width:75px;" v-model="form.isClock" label="1" >是</el-radio>
          <el-radio style="width:75px;" v-model="form.isClock" label="0">否</el-radio>
        </el-form-item>

        <el-form-item label="籍贯" prop="nativePlace">
          <el-input style="width: 180px" v-model="form.nativePlace" placeholder="请输入籍贯"/>
        </el-form-item>

        <el-form-item label="政治面貌" prop="politicalOutlook">
          <el-select v-model="form.politicalOutlook" placeholder="请选择" style="width: 180px">
            <el-option
              v-for="item in politics"
              :key="item.dictLabel"
              :label="item.label"
              :value="item.dictLabel">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="婚姻" prop="marriage">
          <el-select v-model="form.marriage" placeholder="请选择" style="width: 180px">
            <el-option
              v-for="item in hun"
              :key="item.dictSort"
              :label="item.label"
              :value="item.dictLabel">
            </el-option>
          </el-select>

        </el-form-item>

        <el-form-item label="健康状况" prop="healthStatus">
          <el-radio style="width:75px;" v-model="form.healthStatus" v-for="(item,index) in kanga" :key="index"
                    :label="item.dictValue">{{ item.dictLabel }}
          </el-radio>
        </el-form-item>

        <el-form-item label="身份证号码" prop="idCardNumber">
          <el-input style="width: 180px" v-model="form.idCardNumber" placeholder="请输入身份证号码"/>
        </el-form-item>


        <el-form-item label="学历" prop="education">
          <el-select v-model="form.education" placeholder="请选择" style="width: 180px">
            <el-option
              v-for="item in education"
              :key="item.dictSort"
              :label="item.label"
              :value="item.dictLabel">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="入学时间" prop="admissionTime">
          <el-date-picker
            style="width: 180px;"
            v-model="form.admissionTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入学时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduationTime">
          <el-date-picker
            style="width: 180px"
            v-model="form.graduationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择毕业时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="所学专业" prop="speciality">
          <el-input style="width: 180px" v-model="form.speciality" placeholder="请输入所学专业"/>
        </el-form-item>
        <el-form-item label="毕业院校" prop="graduationSchool">
          <el-input style="width: 180px" v-model="form.graduationSchool" placeholder="请输入毕业院校"/>
        </el-form-item>

        <el-form-item label="联系电话" prop="telephone">
          <el-input style="width: 180px" v-model="form.telephone" placeholder="请输入联系电话"/>
        </el-form-item>

        <el-form-item label="紧急联系人名称" prop="contactName">
          <el-input style="width: 180px" v-model="form.contactName" placeholder="紧急联系人名称"/>
        </el-form-item>

        <el-form-item label="紧急联系人关系" prop="relationship">
          <el-input style="width: 180px" v-model="form.relationship" placeholder="请输入紧急联系人关系"/>
        </el-form-item>

        <el-form-item label="紧急联系人电话" prop="contactTelephone">
          <el-input style="width: 180px" v-model="form.contactTelephone" placeholder="请输入紧急联系人电话"/>
        </el-form-item>

        <el-form-item label="个人技能" prop="skill">
          <el-input style="width: 180px" v-model="form.skill" placeholder="请输入技能"/>
        </el-form-item>

        <el-form-item label="入职时间" prop="entryTime">
          <el-date-picker
            style="width: 180px"
            v-model="form.entryTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入入职时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="是否缴纳社保" prop="socialSecurity" style="margin-right: 40px">
          <!--          <el-input    v-model="form.socialSecurity" placeholder="是否缴纳社保" />-->
          <el-radio v-model="form.socialSecurity" label="1">缴纳</el-radio>
          <el-radio v-model="form.socialSecurity" label="2">未缴纳</el-radio>
        </el-form-item>

        <el-form-item v-show="form.socialSecurity==='2'" label="未交社保原因" prop="reason" style="margin-right: 2rem">
          <el-input style="width: 180px" v-model="form.reason" placeholder="请输入原因"/>
        </el-form-item>

        <el-form-item label="是否缴纳商业险" prop="commercialInsurance">
          <el-radio style="width: 75px" v-model="form.commercialInsurance" label="1">缴纳</el-radio>
          <el-radio style="width: 75px;" v-model="form.commercialInsurance" label="2">未缴纳</el-radio>
        </el-form-item>

        <el-form-item label="岗位" prop="post">
<!--          <el-input style="width: 180px" v-model="form.post" placeholder="请输入职务"/>-->
          <el-select
            @change="changepostinfo"
            v-model="form.post"
            :multiple="false"
            filterable
            remote
            reserve-keyword
            placeholder="请输入岗位"
            :remote-method="getpostinfolist"
            :loading="loading">
            <el-option
              v-for="item in postinfolist"
              :key="item.id"
              :label="item.postName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

<!--        <el-form-item label="试用薪资" prop="probationSalary">-->
<!--          <el-input style="width: 180px" v-model="form.probationSalary" placeholder="请输入试用薪资"/>-->
<!--        </el-form-item>-->

<!--        <el-form-item label="转正薪资" prop="fullMemberSalay">-->
<!--          <el-input style="width: 180px" v-model="form.fullMemberSalay" placeholder="请输入转正薪资"/>-->
<!--        </el-form-item>-->

        <el-form-item label="劳动合同签约时间" prop="contractStartTime">
          <el-date-picker
            style="width: 180px"
            v-model="form.contractStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入劳动合同签约时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="劳动合同终止时间" prop="contractEndTime">
          <el-date-picker
            style="width: 180px"
            v-model="form.contractEndTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入入职时间">
          </el-date-picker>
        </el-form-item>


        <el-form-item label="邮箱">
          <el-input style="width: 180px" v-model="form.email" placeholder="请输入邮箱"/>
        </el-form-item>
        <!--        <el-form-item label="状态"  prop="status"  >-->
        <!--          <el-radio v-model="form.status" label="0">待入职</el-radio>-->
        <!--          <el-radio v-model="form.status" label="1">在职</el-radio>-->
        <!--          <el-radio v-model="form.status" label="2">休假</el-radio>-->
        <!--          <el-radio v-model="form.status" label="3">离职</el-radio>-->
        <!--        </el-form-item>-->


        <el-form-item label="开户行" prop="bank">
          <el-input style="width: 180px" v-model="form.bank" placeholder="请输入开户行"/>
        </el-form-item>

        <el-form-item label="银行卡号" prop="bankCardNo">
          <el-input style="width: 180px" v-model.number="form.bankCardNo" placeholder="请输入银行卡号"/>
        </el-form-item>

        <el-form-item label="离职日期" prop="leaveDate">
          <el-date-picker
            style="width: 180px"
            v-model="form.leaveDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="离职日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="曾任职公司" prop="previousCompany">
          <el-input
            style="width: 180px"
            v-model="form.previousCompany"
            placeholder="请输入曾任职公司"
            clearable
          ></el-input>
        </el-form-item>

        <el-form-item label="曾任职岗位" prop="previousPosition">
          <el-input
            style="width: 180px"
            v-model="form.previousPosition"
            placeholder="请输入曾任职岗位"
            clearable
          ></el-input>
        </el-form-item>

        <el-form-item label="离职原因">
          <el-input
            style="width:480px"
            v-model.trim="form.reasonsForLeaving"
            placeholder="请输入离职原因"
            clearable
            type="textarea"
          ></el-input>
        </el-form-item>


        <el-form-item label="离职证明照片" prop="leavingCertificatePhotos">
          <uplod v-model="form.leavingCertificatePhotos"></uplod>
        </el-form-item>
        <el-form-item label="学历照片" prop="educationalPhotos">
          <uplod v-model="form.educationalPhotos"></uplod>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="70%">
      <img width="100%" height="600px" :src="'http://t6564w.natappfree.cc'+leave" alt="">
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible=false">确 定</el-button>
  </span>
    </el-dialog>

    <el-dialog title="员工经历" :visible.sync="showdilg">
      <el-table :data="historyList">
        <el-table-column label="姓名" align="center" prop="name"/>
        <el-table-column label="曾任职公司" align="center" prop="previousCompany"/>
        <el-table-column label="曾任职岗位" align="center" prop="previousPosition"/>
        <el-table-column label="起始时间" align="center" prop="startTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="离职时间" align="center" prop="endTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="离职原因" align="center" prop="reasonsForLeaving"/>
      </el-table>
    </el-dialog>


    <!--    员工详情弹出-->
    <el-dialog
      title="员工详情"
      :visible.sync="DetailPages"
      width="30%">
      <el-collapse v-model="activeName" >
        <el-collapse-item title="员工基本信息" name="1">
          <div>姓名：{{ Detaillist.name }}</div>
          <div>职称：{{ Detaillist.title }}</div>
          <div>籍贯：{{ Detaillist.nativePlace }}</div>
          <div>身份证号码：{{ Detaillist.idCardNumber }}</div>
          <div>健康状况：{{ Detaillist.healthStatus }}</div>
          <div>政治面貌：{{ Detaillist.politicalOutlook }}</div>
          <div>婚姻：{{ Detaillist.marriage }}</div>
          <div>技能：{{ Detaillist.skill }}</div>
          <div>邮箱：{{ Detaillist.email }}</div>
          <div>部门:{{ Detaillist.deptName }}</div>
        </el-collapse-item>

        <el-collapse-item title="员工学历信息" name="6">
          <div>学历信息：{{ Detaillist.education }}</div>
          <div>所学专业：{{ Detaillist.speciality }}</div>
          <div>毕业院校：{{ Detaillist.graduationSchool }}</div>
          <div>入学时间：{{ parseTime(Detaillist.admissionTime, '{y}-{m}-{d}') }}</div>
          <span>学历照片：  <a :href="url+`${Detaillist.educationalPhotos}`" style="color: #00afff">查看图片</a> </span>
          <div>是否缴纳社保：{{ Detaillist.socialSecurity }}</div>
          <div>是否缴纳商业险：{{ Detaillist.commercialInsurance }}</div>
          <div>开户行：{{ Detaillist.bank }}</div>
          <div>银行卡号：{{ Detaillist.bankCardNo }}</div>
        </el-collapse-item>

        <el-collapse-item title="紧急联系方式" name="13">
          <div>紧急联系人名称：{{ Detaillist.contactName }}</div>
          <div>紧急联系人关系：{{ Detaillist.relationship }}</div>
          <div>紧急联系人电话{{ Detaillist.contactTelephone }}</div>
        </el-collapse-item>

        <el-collapse-item title="合同期限" name="22">
          <div>劳动合同签约时间：{{ parseTime(Detaillist.contractStartTime, '{y}-{m}-{d}') }}</div>
          <div>劳动合同终止时间：{{ parseTime(Detaillist.contractEndTime, '{y}-{m}-{d}') }}</div>
        </el-collapse-item>
        <el-collapse-item title="离职日期" name="23">
          <div>离职日期：{{ parseTime(Detaillist.leaveDate, '{y}-{m}-{d}') }}</div>
         <span>离职证明照片: <a :href="url+`${Detaillist.leavingCertificatePhotos}`" style="color: #00afff"> 查看图片</a></span>

        </el-collapse-item>


      </el-collapse>

    </el-dialog>

    <el-dialog
      title="修改状态"
      :visible.sync="statexiu"
      width="30%">
      <el-select v-model="statexiugai" placeholder="请选择">
        <el-option
          v-for="item in state"
          :key="item.dictLabel"
          :label="item.dictLabel"
          :value="item.dictValue">
        </el-option>
      </el-select>


      <span slot="footer" class="dialog-footer">
    <el-button @click="statexiu = false">取 消</el-button>
    <el-button type="primary" @click="xiugaifn">确 定</el-button>
  </span>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <import-user ref="user" @showUser="showUser"></import-user>
  </div>
</template>

<script>
import {exportStaffApi,staffStatus,listStaff, getStaff, delStaff, addStaff, updateStaff} from "@/api/module/staff";
import uplod from "@/components/ImageUpload"
import {getDicts} from "@/api/system/dict/data.js"
import Eselect from "@/components/ELselect/Elselect"
//经历接口
import {addHistory, listHistory} from "@/api/module/history";
import Logo from "@/layout/components/Sidebar/Logo";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {deptTreeSelect} from "@/api/system/user";
import {getToken} from "@/utils/auth";
import {listPost, updatePost} from "@/api/system/post";
import {exportFile} from '../common/common'
import {listPostInfo} from "@/api/module/postInfo";
import importUser from "@/views/dialog/user";
import {listDept} from "@/api/system/dept";



export default {
  name: "Staff",
  dicts: ['is_clock'],

  components: {
    uplod,
    Eselect,
    Treeselect,
    importUser
  },
  data() {
    //自定义校验定义方法
    let identity = (rule, value, callback) => {
      const reg = /^[1-8]\d{5}(18|19|20)\d{2}(0[1-9]|10|11|12)(0[1-9]|[1-2][0-9]|30|31)\d{3}[0-9Xx]$/
      if (!reg.test(value)) {
        return callback(new Error('请输入正确的身份证号'));
      } else {
        callback()
      }
    }
    return {
      moduleform:{
        id:'',//员工id
        status:'',//入职状态
      },//关联员工打卡模型
      //部门选择
      deptOptions: [],
      deptlist:[],
      postlist:[],//职级
      optionsProp:{value:'id',label:'label',children:'children'},
      value:[],
      historyqueryParams: {
        pageNum: 1,
        pageSize: 10,
        staffId: null,//员工id
        name: null,//姓名
        previousCompany: null,//曾任职公司
        previousPosition: null,//曾任职岗位
        startTime: null,//起始时间
        endTime: null,//离职时间
        reasonsForLeaving: null,//离职原因
        delFlag: null
      },
      // 修改状态弹框
      statexiu: false ,
      statexiugai:'',
      activeName: 1,
      //详情数据
      xqdetail: "",
      //健康
      kanga: "",
      //状态
      state: "",
      //社保
      zdsocial: "",
      //商业险
      commercial: "",
      //员工经历 弹出框
      showdilg: false,
      //弹出框子
      dialogVisible: false,
      //离职图片
      leave: null,
      //字典学历
      education: {},
      //字典婚姻
      hun: {},
      //员工类型
      staffTypeEnum: {},
      //字典党员数据
      politics: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工管理表格数据
      staffList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //员工详情弹出
      DetailPages: false,
      //详情数据
      Detaillist:{},
      //修改id
      xiuid:"",
      //部门
      bumen:"",
      clockEnum:"",
      xiuform:{

      },
      customOpen:false,
      checkList:[],
      fields:{
        fieldsNames:''
      },//自定义导出
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        gender: null,
        age: null,
        birthday: null,
        nativePlace: null,
        politicalOutlook: null,
        marriage: null,
        education: null,
        height: null,
        weight: null,
        healthStatus: null,
        speciality: null,
        title: null,
        idCardNumber: null,
        graduationSchool: null,
        admissionTime: null,
        graduationTime: null,
        telephone: null,
        address: null,
        contactName: null,
        relationship: null,
        contactTelephone: null,
        personalPhotos: null,
        educationalPhotos: null,
        otherCertificatePhotos: null,
        skill: null,
        entryTime: null,
        socialSecurity: null,
        reason: null,
        commercialInsurance: null,
        post: null,
        probationSalary: null,
        fullMemberSalay: null,
        contractStartTime: null,
        contractEndTime: null,
        leaveDate: null,
        leavingCertificatePhotos: null,
        email: null,
        status: null,
        bank: null,
        bankCardNo: null,
        dept: null,
        deptName: null,
        tenantId: null,
        userId: null,
        prize: null,
        selfEvaluation: null,
        expect: null,
        company:null,
        staffRank:null,
        staffType:null,
        clockTime:null,
        isClock:null,
      },
      // 表单参数
      form: {
        name: "1"
      },
      // 列信息
      columns: [
        { key: 0, label: `姓名`, visible: true },
        { key: 1, label: `性别`, visible: true },
        { key: 2, label: `年龄`, visible: true },
        { key: 3, label: `部门`, visible: true },
        { key: 4, label: `身份证号码`, visible: true },
        { key: 5, label: `联系电话`, visible: true },
        { key: 6, label: `入职时间`, visible: true },
        { key: 7, label: `合同签约时间`, visible: true },
        { key: 8, label: `合同终止时间`, visible: true },
        { key: 9, label: `邮箱`, visible: true },
        { key: 10, label: `状态`, visible: true },
        { key: 11, label: `修改状态`, visible: true },
        { key: 12, label: `员工详情`, visible: true },
        { key: 13, label: `员工经历`, visible: true },
      ],
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "module/staff/importCustomer"
      },
      url:process.env.VUE_APP_BASE_API,
      // 表单校验
      rules:
        {
          previousCompany: [
            {required: true, message: '请输入曾就职公司', trigger: 'blur'},
          ],
          previousPosition: [
            {required: true, message: '请输入曾就职公司', trigger: 'blur'},
          ],
          name: [
            {required: true, message: '请输入姓名', trigger: 'blur'}
          ],
          gender: [
            {required: true, message: '请选择性别', trigger: 'blur'},
          ],
          // age: [
          //   {required: true, message: '请输入年龄', trigger: 'blur'},
          // ],
          // title: [
          //   {required: true, message: '请输入职位', trigger: 'blur'},
          // ],
          birthday: [
            {required: true, message: '请选择日期', trigger: 'blur'},
          ],
          nativePlace: [
            {required: true, message: '请输入籍贯', trigger: 'blur'},
          ],
          politicalOutlook: [
            {required: true, message: '请输入政治面貌', trigger: 'blur'},
          ],
          marriage: [
            {required: true, message: '请输入婚姻', trigger: 'blur'},
          ],
          healthStatus: [
            {required: true, message: '请输入健康状况', trigger: 'blur'},
          ],
          idCardNumber: [
            {required: true, validator: identity, trigger: 'blur'},
          ],
          education: [
            {required: true, message: '请输入学历', trigger: 'blur'},
          ],
          admissionTime: [
            {required: true, message: '请输入学时间', trigger: 'blur'},
          ],
          speciality: [
            {required: true, message: '请输入所学专业', trigger: 'blur'},
          ],
          graduationSchool: [
            {required: true, message: '请输入毕业院校', trigger: 'blur'},

          ],
          telephone: [
            {required: true, message: '请输入联系电话', trigger: 'blur'},
          ],
          contactName: [
            {required: true, message: '紧急联系人名称', trigger: 'blur'},
          ],
          relationship: [
            {required: true, message: '请输入紧急联系人关系', trigger: 'blur'},

          ],
          contactTelephone: [
            {required: true, message: '请输入紧急联系人电话', trigger: 'blur'},

          ],
          skill: [
            {required: true, message: '请输入技能', trigger: 'blur'},

          ],
          entryTime: [
            {required: true, message: '请输入入职时间', trigger: 'blur'},

          ],
          socialSecurity: [
            {required: true, message: '请选择缴纳社保', trigger: 'blur'},

          ],
          commercialInsurance: [
            {required: true, message: '请选择是否缴纳商业险', trigger: 'blur'},

          ],
          post: [
            {required: true, message: '请输入岗位', trigger: 'blur'},
          ],
          probationSalary: [
            {required: true, message: '请输入试用薪资', type: 'number', trigger: 'blur'},

          ],
          fullMemberSalay: [
            {required: true, message: '请输入转正薪资', type: 'number', trigger: 'blur'},

          ],
          contractStartTime: [
            {required: true, message: '请输入活动名称', trigger: 'blur'},
          ],
          contractEndTime: [
            {required: true, message: '请输入离职日期', trigger: 'blur'},
          ],
          email: [
            {required: true, message: '请输入邮箱', trigger: 'blur'},

          ],
          bank: [
            {required: true, message: '请输入开户行', trigger: 'blur'},

          ],
          bankCardNo: [
            {required: true, message: '请输入卡号', type: 'number', trigger: 'blur'},
          ],
          leavingCertificatePhotos: [
            {required: true, message: '请传入离职证明照片', trigger: 'blur'},
          ],
          status: [
            {required: true, message: '请选择状态', trigger: 'blur'},
          ],
          deptName: [
            {required: true, message: '请输入部门', trigger: 'blur'},
          ],
          educationalPhotos: [
            {required: true, message: '请上传学历照片', trigger: 'blur'}
          ],
          company: [
            {required: true, message: '请输入公司', trigger: 'blur'},
          ],
          staffRank: [
            {required: true, message: '请输入职级', trigger: 'blur'},
          ],
          staffType: [
            {required: true, message: '请输入类型', trigger: 'blur'},
          ],
          isClock: [
            {required: true, message: '请输入是否打卡', trigger: 'blur'},
          ],
        },
      // 经历数据
      historyList: [],
      postinfolist:[],//岗位
      //经历提交数据的form
      histrform: {},
      sexOptions: [],
    };
  },

  async created() {
    // 获得字典数据
    await this.getSexOptions()
    this.getList();
    this.getdeptlist();
    this.getpostinfolist();
    this.getpostlist();
    //获取经历数据
    // this.gethistoryList()
  },
  methods: {
    //获取职级
    getpostlist(){
      listPost().then(res=>{
        this.postlist=res.rows
      })
    },
    changepost(val){
      this.postlist.forEach(item=>{
        if(item.postId==val){
          this.form.staffRank=item.postName
        }
      })
    },
    //获取岗位
    getpostinfolist(query){
      listPostInfo({postName:query}).then(res=>{
        this.postinfolist=res.rows
      })

    },
    changepostinfo(val){
      this.form.post=val
      this.postinfolist.forEach(item=>{
        if(item.id==val){
          this.form.postName=item.postName
        }
      })
    },
    //获取部门列表
    async getdeptlist(){
      let res=await deptTreeSelect()
      this.deptlist=res.data
    },
    handleChange(value){
      /*  this.form.company*/
      this.form.dept=value[2]
      this.getlcompany(this.deptlist,value[1],this.form.company)
      this.getdeptlabel(this.deptlist,value[2],this.form.company)
    },
    //遍历数组
    getlcompany(arr,value,label){
      var newlabel=''
      for(var i=0;i<arr.length;i++){
        if(arr[i].id==value){
          newlabel=arr[i].label
          this.form.company=arr[i].label
        }
        if(arr[i].children){
          this.getlcompany(arr[i].children,value,label)
        }
      }
    },
    getdeptlabel(arr,value,label){
      arr.forEach(item=>{
        if(item.id==value){
          label=item.label
          this.form.deptName=item.label
          return
        }
        if(item.children){
          this.getdeptlabel(item.children,value,label)
        }
      })
    },
    openusername(val){
      this.$refs.user.show(val)
    },
    showUser(data){
      if(data.type=='0'){
        //自定义类型赋值
        this.form.userId=data.userId
        this.form.userName=data.userName
        this.form.name=data.userName
      }
    },
    //自定义操作
    handleCustomExport(){
      this.customOpen=true
    },
    async getinfo(){

      this.fields.fieldsNames= this.checkList.join()
      //{fieldsNames:'username,applicationType'}
      exportStaffApi({fieldsNames: this.fields.fieldsNames}).then((res)=>{
        const fileName = '员工报表'
        const contentType =
          'application/vnd.ms-excel'
        exportFile(res, contentType, fileName)
      })
        .catch((err) => {
          console.log(err)
        })
      this.checkList=[]
      this.customOpen=false
    },
    //上移
    async upFn(index,row){

      this.form=row
      this.form.sort--
      await updateStaff({id:this.form.id,sort:this.form.sort})
      index--
      console.log(index)
      let item= this.staffList[index]
      item.sort++
      await updateStaff({id:item.id,sort:item.sort})
      await this.getList()
    },
    async downFn(index,row){
      this.form=row
      this.form.sort++
      await updateStaff({id:this.form.id,sort:this.form.sort})
      index++
      let item=this.staffList[index]
      item.sort--
      await updateStaff({id:item.id,sort:item.sort})
      await this.getList()
    },
    //打开员工经理
   async  openStaffHistoy(val){
      this.showdilg=true
      let res=await listHistory({name:val.name,id:val.id})
     this.historyList=res.rows
    },

    //传入字典数据 与需要转换的 给你自动做转换
    getValue(arr, item) {
      for (let i = 0; i < arr.length; i++) {
        if (item === arr[i].dictValue) {
          return arr[i].dictLabel
        }
      }
    },
    //获取经历数据
    gethistoryList() {
      // this.loading = true;
      listHistory(this.historyqueryParams).then(response => {
        // console.log(response)
        this.historyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 查询员工管理表 */
    getList() {
      this.loading = true;
      listStaff(this.queryParams).then(response => {
        this.staffList = response.rows;
        this.total = response.total;
        this.loading = false;

        let arr = this.staffList
        arr.forEach(item => {
          item.gender = this.getValue(this.sexOptions, item.gender)
          item.socialSecurity = this.getValue(this.zdsocial, item.socialSecurity)
          item.commercialInsurance = this.getValue(this.commercial, item.commercialInsurance)
          item.status = this.getValue(this.state, item.status)
          item.healthStatus = this.getValue(this.kanga, item.healthStatus)
          item.isClock=this.getValue(this.clockEnum,item.isClock)
        })
        this.staffList = arr
      });
    },
    async deptTreeSelectfn(){
      const res = await deptTreeSelect()
      this.deptOptions= res.data
    },
    //字典获取数据
    async getSexOptions() {
      let res = await getDicts('sys_user_sex')
      this.sexOptions = res.data

      //社保
      const datb = await this.getDicts('social')
      this.zdsocial = datb.data

      //政治面貌
      const resa = await this.getDicts('politics_status')
      this.politics = resa.data
      //婚姻
      const data = await this.getDicts('marriage')
      this.hun = data.data

      //员工类型
      const staffTypeData = await this.getDicts('staff_type')
      this.staffTypeEnum = staffTypeData.data

      //学历
      const education = await this.getDicts('education')
      this.education = education.data

      //商业险
      const commercial = await this.getDicts('commercial')
      this.commercial = commercial.data

      //状态
      const status = await this.getDicts('state')
      this.state = status.data

      //健康
      const kang = await this.getDicts('kang')
      console.log(kang)
      this.kanga = kang.data

    //  部门
      const bumen = await this.getDicts('staffsection')
      this.bumen = bumen.data

      //  是否打卡
      const clockEnum = await this.getDicts('is_clock')
      this.clockEnum = clockEnum.data

    },
    //查看详情筛选
    DetailPagesfn(val) {
      console.log(val)
      this.DetailPages = true
      this.Detaillist=val
      // console.log(val)
      // const res = this.staffList.filter(item => item.id === val.id)
      // this.Detaillist = res
    },
    //图片回显
    tufn(val) {
      this.leave = val
      this.dialogVisible = true
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.value=[]
      this.form = {
        //id
        id: null,
        // 姓名
        name: null,
        // 性别
        gender: null,
        //岁数
        age: null,
        //生日
        birthday: null,
        //籍贯
        nativePlace: null,
        //政治面貌
        politicalOutlook: null,
        //婚姻
        marriage: null,
        //学历
        education: null,
        //高
        height: null,
        //宽
        weight: null,
        //健康状态
        healthStatus: null,
        //所学专业
        speciality: null,
        //岗位
        title: null,
        rankId: null,
        idCardNumber: null,
        graduationSchool: null,
        admissionTime: null,
        graduationTime: null,
        telephone: null,
        address: null,
        contactName: null,
        relationship: null,
        contactTelephone: null,
        personalPhotos: null,
        educationalPhotos: null,
        otherCertificatePhotos: null,
        skill: null,
        entryTime: null,
        socialSecurity: null,
        reason: null,
        commercialInsurance: null,
        post: null,
        probationSalary: null,
        fullMemberSalay: null,
        contractStartTime: null,
        contractEndTime: null,
        leaveDate: null,
        leavingCertificatePhotos: null,
        email: null,
        status: null,
        delFlag: null,
        bank: null,
        bankCardNo: null,
        dept: null,
        deptName: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        tenantId: null,
        userId: null,
        prize: null,
        selfEvaluation: null,
        company:null,
        staffRank:null,
        staffType:null,
        isClock:null,
        postId:null,
        clockTime:null,
        expect: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      listDept(this.queryParams).then(response => {
        this.deptList = this.normalizer(response.data)
        this.loading = false;
      });
      this.title = "添加员工管理";
      this.form.status = 0
      this.deptTreeSelectfn()
    },
    /** 转换部门数据结构 */
    normalizer(item) {
      console.log(item)
      item.forEach((node)=>{
        node.id=node.dept,
          node.label=node.deptName,
          node.children= node.children
      })
      return item

    },
    // 处理回显数据
    getcomponylist(val,arry){
      arry.forEach(item=>{
        if(item.label==val){
          this.value.push(Number(item.id))
          console.log("333333:"+item.id);
          return
        }
        if(item.children){
          this.getcomponylist(val,item.children)
        }
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStaff(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.value=[100]
        this.getcomponylist(this.form.company,this.deptlist)
        this.value.push(this.form.dept)
        this.title = "修改员工管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStaff(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              console.log(12)
            });
          } else {
            this.histrform.name = this.form.name
            this.histrform.startTime = this.form.entryTime
            this.histrform.endTime = this.form.leaveDate
            this.histrform.previousCompany = this.form.previousCompany
            this.histrform.reasonsForLeaving = this.form.reasonsForLeaving
            this.histrform.previousPosition = this.form.previousPosition
            addStaff(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
            addHistory(this.histrform)
            this.gethistoryList()
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除员工管理编号为"' + ids + '"的数据项？').then(function () {
        return delStaff(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('module/staff/export', {
        ...this.queryParams
      }, `staff_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('module/staff/importTemplate', {
      }, `staff_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
   async statefn(val) {
     console.log(val)
     console.log('111')
     this.moduleform.id=val.id

     this.statexiu=true

     this.xiuid=val.id
    },
    async xiugaifn(){
      if(this.statexiugai.length>0){
        this.xiuform.id=this.xiuid
        this.xiuform.status=this.statexiugai
        this.moduleform.status=this.statexiugai

        const res = await updateStaff(this.xiuform)
        // console.log(res)
        this.$message({
          message: '修改成功',
          type: 'success'
        });
        const data=staffStatus(this.moduleform)
        console.log(data)
        this.statexiu=false
        this.getList()
      }else{
        this.$message({
          message: '请选择状态',
          type: 'warning'
        });
      }
    }
  }
};
</script>
<style>
.checkBox{
  display: flex;
  flex-wrap: wrap;
}
.checkBox .label{
  width: 25%;
  height: 30px;
  /*background-color: red;*/
}
</style>
